
*Sorting CCD Enrollment Data*

import delimited using "ag13yr.txt", clear

gen str7 leaidstr=string(leaid,"%07.0f")

gen statefip=substr(leaidstr,1,2)

destring statefip, replace

drop leaidstr

rename leaid ncesid

keep if statefip==21

joinby ncesid using kydistcntycrosswalk.dta, unmatched(master)

tab _merge

drop _merge

keep ncesid countyfip member*

reshape long member, i(ncesid) j(year)

gen str2 yearstr=string(year,"%02.0f")

rename year yearpart

gen year="19" + yearstr

destring year, replace

replace year=year+1

drop yearpart yearstr

order ncesid year

rename member enrollmentccd

label var enrollmentccd "District Enrollment from Common Core of Data"

save distenrollmentccd.dta, replace

collapse (sum) enrollmentccd, by(countyfip year)

label var enrollmentccd "County Enrollment from Common Core of Data"

save cntyenrollmentccd.dta, replace

clear
